<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layouts/template.xhtml">
	<ui:define name="body">
		<h:form id="form" acceptcharset="ISO-8859-1">
			<p:panel header="#{msgs['massai.productionGroup.header.consult']}">
			
				<h:panelGrid style="width: 100%;">
					<p:commandButton value="#{msgs['common.register']}" action="productionGroupRegister" 
						ajax="false" immediate="true" styleClass="buttonNew" tabindex="1"
						rendered="#{sessionBean.showAction('supportProductionGroup', 'insert')}" />
				</h:panelGrid>

				<fieldset>
					<legend><h:outputText value="#{msgs['common.search.filter']}" /></legend>
					<h:panelGrid>
						<p:outputLabel value="#{msgs['massai.productionGroup.name']}" for="name" />
						<p:inputText id="name" tabindex="2" value="#{productionGroupBean.productionGroup.nameGroup}" 
							style="width: 350px;" maxlength="100" />
					</h:panelGrid>

					<h:panelGrid>
						<p:commandButton tabindex="3" value="#{msgs['common.search']}" 
							ajax="true" actionListener="#{productionGroupBean.find()}" update="form"
							rendered="#{sessionBean.showAction('supportProductionGroup', 'search')}" />
					</h:panelGrid>
				</fieldset>

				<p:spacer height="20px" />

				<p:dataTable var="prod" value="#{productionGroupBean.dataModel}" rows="10" paginator="true" paginatorPosition="bottom"
					paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
					currentPageReportTemplate="{currentPage} de {totalPages}" rowsPerPageTemplate="5,10,20"
					id="dataTable" lazy="true" rowIndexVar="rowIndex" emptyMessage="#{msgs['common.no.record.found']}">
					<f:facet name="header"><p:outputLabel value="#{msgs['massai.productionGroup.list']}" /></f:facet>

                    <p:column headerText="#{msgs['massai.productionGroup.name']}" sortBy="#{prod.nameGroup}">
                        <h:outputText value="#{prod.nameGroup}" />
                    </p:column>
                    
                    <p:column headerText="#{msgs['common.delete']}" width="60" style="text-align: center;"
                    	rendered="#{sessionBean.showAction('supportProductionGroup', 'delete')}">
						<h:commandLink id="delete"
							onclick="if (!window.confirm('Deseja excluir esse registro?') ) {return false}" 
			            	actionListener="#{productionGroupBean.delete(prod)}">
							<img src="#{facesContext.externalContext.requestContextPath}/images/ico_remove.png" 
								width="16" height="16" border="0" name="#{msgs['common.delete']}" 
								alt="#{msgs['common.delete']}" id="icoRemove"
								title="#{msgs['common.delete']}" />
						</h:commandLink>
					</p:column>

                    <p:column headerText="#{msgs['common.detail']}" width="50" style="text-align: center;"
                    	rendered="#{sessionBean.showAction('supportProductionGroup', 'search')}">
						<p:commandLink id="detail" oncomplete="PF('groupDlg').show()" update=":formGroup" tabindex="4">
							<img src="#{facesContext.externalContext.requestContextPath}/images/ico_detail.png" 
								width="16" height="16" border="0" name="#{msgs['common.detail']}" 
								title="#{msgs['common.detail']}" alt="#{msgs['common.detail']}" />
							<f:setPropertyActionListener target="#{productionGroupBean.loadModal}" value="#{prod}"/>
						</p:commandLink>
					</p:column>

					<p:column headerText="#{msgs['common.update']}" width="32" style="text-align: center;" 
						rendered="#{sessionBean.showAction('supportProductionGroup', 'update')}">
						<h:link outcome="productionGroupRegister" tabindex="5">
							<img src="#{facesContext.externalContext.requestContextPath}/images/ico_edit.png" 
								width="16" height="16" border="0" name="#{msgs['common.update']}" 
								title="#{msgs['common.update']}" alt="#{msgs['common.update']}" id="icoEdit" />
							<f:param name="param" value="#{prod.id}" />
						</h:link>
					</p:column>
                </p:dataTable>
			</p:panel>
		</h:form>
		
		<p:dialog header="#{msgs['massai.productionGroup.detail.header']}" position="center top" style="margin: 5px;" height="75%"
			id="groupDlg" widgetVar="groupDlg" resizable="false" closeOnEscape="true" modal="true" width="70%" showEffect="fade">
			<h:form id="formGroup" acceptcharset="ISO-8859-1">
				<h:panelGroup style="padding: 20px;">
					<p:panel header="#{msgs['massai.productionGroup.detail.header']}">
						<h:panelGrid>
							<h:outputLabel value="#{msgs['massai.productionGroup.description']}" />
							<h:outputText value="#{productionGroupBean.productionGroupModal.nameGroup}" />
						</h:panelGrid>
					</p:panel>

					<p:spacer height="15px" />

					<p:dataTable id="dataTableDepart" emptyMessage="#{msgs['common.no.record.found']}" 
						value="#{productionGroupBean.productionGroupModal.departments}" var="depart" sortMode="multiple" rows="5" paginator="true"
		                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
		                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false">

		                <f:facet name="header"><h:outputText value="#{msgs['massai.productionGroup.departments']}" /></f:facet>

						<p:column headerText="#{msgs['massai.productionGroup.code']}" width="80" sortBy="#{depart.code}">
							<h:outputText value="#{depart.codeEmp} - #{depart.codeDepartment}" />
						</p:column>

						<p:column headerText="#{msgs['massai.productionGroup.name']}" width="100" sortBy="#{depart.alternativeName}">
							<h:outputText value="#{depart.alternativeName}" />
						</p:column>
					</p:dataTable>

					<p:dataTable style="margin-top: 15px;" emptyMessage="#{msgs['common.no.record.found']}" sortMode="multiple" rows="10" 
						value="#{productionGroupBean.productionGroupModal.groupItems}" var="item" paginator="true" paginatorAlwaysVisible="false"
		                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
		                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom">
		                
		                <f:facet name="header"><h:outputText value="#{msgs['massai.productionGroup.groupItems']}" /></f:facet>

		                <p:column headerText="#{msgs['massai.productionGroup.level']}" width="60" sortBy="#{item.serviceItem.levelService}">
							<h:outputText value="#{item.serviceItem.categoryLevel.code}.#{serviceItemBean.completedZerosLeft(item.serviceItem.levelService, 3)}" />
						</p:column>

						<p:column headerText="#{msgs['massai.productionGroup.description']}" sortBy="#{item.serviceItem.description}">
							<h:outputText value="#{item.serviceItem.description}" />
						</p:column>

						<p:column headerText="#{msgs['massai.productionGroup.unitMeasure']}" width="140" sortBy="#{item.serviceItem.unitMeasure.acronym}">
							<h:outputText value="#{item.serviceItem.unitMeasure.acronym} - #{item.serviceItem.unitMeasure.nameMeasure}" />
						</p:column>

						<p:column headerText="#{msgs['massai.productionGroup.unitValue']}" width="80" sortBy="#{item.unitValue}">
							<h:outputText value="#{item.unitValue}">
								<f:convertNumber maxFractionDigits="2" minFractionDigits="2" pattern="R$ #,##0.00" />
							</h:outputText>
						</p:column>
					</p:dataTable>
				</h:panelGroup>
			</h:form>
	    </p:dialog>
	</ui:define>
</ui:composition>
</html>